<template>
  <div class="searchTable">
    <a-modal title="选择规范清单" :visible="visibleSpecific" width="65%" :confirm-loading="confirmLoading" @ok="handleOk" @cancel="handleCancel">
      <searchData :searchData="searchArr" @search="search"></searchData>
      <a-table  :row-selection="rowSelection" :columns="columns" :data-source="specificData" :pagination="false"> </a-table>
      <pagination :total="totalSize" v-model="pageNum" :pageSize.sync="pageSize" @change="handlePageChange" @showSizeChange="showSizeChange"></pagination>
    </a-modal>
  </div>
</template>
<script>
import { columns2 } from './model'
let spliceColumns = columns2.slice(0, 6)
import { getTableList, technicalProjectStandardDetailedList } from '@/api/technical/specificationList'
const searchArr = [
  {
    name: '图集/标准号',
    value: 'atlasStandardNumber',
    type: 'input'
  },
  {
    name: '图集名称',
    value: 'atlasName',
    type: 'input'
  }
]
export default {
  name: 'choiceSpecific',
  props: {
    visibleSpecific: {
      type: Boolean,
      default: false
    },
    queryParam: {
      type: Object,
      default: {}
    }
  },
  data() {
    this.columns = spliceColumns
    this.searchArr = searchArr
    return {
      specificData: [],
      confirmLoading: false,
      choiceSpecificData: [],
      selectedRowKeys: [],
      totalSize: 0,
      pageNum: 1,
      pageSize: 10,
      ids: [],
      childQueryParam:{},
      showTrue:false
    }
  },
  computed: {
    // 与父组件绑定visible
    dialogVisible: {
      get: function () {
        return this.visibleSpecific
      },
      set: function (e) {
        this.$emit('update:visibleSpecific', e)
      }
    },
    rowSelection() {
      const { selectedRowKeys } = this;
      return {
        selectedRowKeys,
        onChange: (selectedRowKeys, idsArr) => {
          this.selectedRowKeys = selectedRowKeys
          this.ids = []
          idsArr.map((item) => this.ids.push(item?.id))
        },
        getCheckboxProps: (record) => ({
          props: {
            disabled: record.isEffective === 1, // Column configuration not to be checked
            name: record.name
          }
        })
      }
    }
  },
  watch: {
    visibleSpecific(e) {
      e && this.getSpecificData(1, 10)
    }
  },
  mounted() {
    this.getSpecificData()
  },
  methods: {
     search(value) {
      value && (this.childQueryParam = value)
       this.getSpecificData()
    },
    async handleOk() {
      if (this.ids.length == 0) {
        this.$error({ content: '至少选中一条数据' })
        return false
      } else {
        let data = await technicalProjectStandardDetailedList(this.ids)
        if (data.data.code == '0') {
          this.$message.success('选择规范清单成功')
          this.selectedRowKeys = []
          this.ids = []
          this.$emit('hideVisible')
        } else {
           this.$error({ content: data.data.msg })
        }
      }
    },
    handleCancel() {
      this.dialogVisible = false
      this.selectedRowKeys = []
      this.ids = []
    },
    async getSpecificData() {
      this.childQueryParam.projectStandardId = this.queryParam.projectStandardId
      this.childQueryParam.groupMenuId =  this.queryParam.groupMenuId
      this.childQueryParam.queryData =1;
      this.childQueryParam.isUsed=1;
      let req = {
        pageNum: this.pageNum,
        pageSize: this.pageSize,
        param: { ...this.childQueryParam }
      }
      let data = await getTableList(req)
      this.totalSize = data.data?.total
      this.specificData = data?.data?.list;
      if(this.specificData.length>0){
         this.showTrue = this.specificData.some((item)=>item.isEffective*1!==1)
      }
    },
    handlePageChange(pageNo, pageSize) {
      this.pageNum = pageNo
      this.getSpecificData()
    },
    showSizeChange(pageNo, pageSize) {
      this.pageSize = pageSize
      this.getSpecificData()
    }
  }
}
</script>
<style lang="less" scoped>
</style>
